/*
Copyright 2008, 2009, 2010 Brightworks, Inc.

This file is part of Language Mentor.

Language Mentor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Language Mentor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Language Mentor.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.langcollab.languagementor.model
{

    /*
    Overview:

    Application consists of multiple 'screens' which may be thought of as existing on a
    grid, eg. 5 screens wide by 5 screens high.

    The currentApplicationState property holds a 3-digit integer, which indicates current screen
    and the screen's state:
    - First digit: horizontal position of current screen in grid
    - Second digit: vertical position of current screen in grid
    - Third digit: state of current screen
    - Example: 330 indicates:
    - the active screen is the third screen from the left, and third from the top
    - this screen is in its '0' state
    */

    import com.brightworks.util.Debug;
    import com.langcollab.languagementor.util.Utils_LangCollab;
    import com.langcollab.languagementor.vo.ChunkVO;
    import com.langcollab.languagementor.vo.ModuleVersionVO;

    import mx.collections.ArrayCollection;

    public class MainModel
    {
        public var audioFileDirectoryURL:String = "";
        [Bindable] public var currentApplicationState:int = 0;
        [Bindable] public var currentLearningModeId:int = 0;
        [Bindable] public var currentRepositoryRootURL:String;
        [Bindable] public var currentRepositoryXML:XML;
        [Bindable] public var currentUserId:int = 1; ///
        [Bindable] public var dataManager:DataManager;   // "Digested" data - ie. indexed etc. data with data structures designed for use by views
        [Bindable] public var dataManagerInitialized:Boolean = false;
        [Bindable] public var learningModeDescriptionsHTML:Object;
        [Bindable] public var moduleSelectionTreeData:ArrayCollection;
        [Bindable] public var screenInfo:ScreenInfo = new ScreenInfo();
        [Bindable] public var selectedChunkIndex:int = 0;
        [Bindable] public var selectedModuleVersionChunksData:ArrayCollection = new ArrayCollection();
        [Bindable] public var selectedModuleVersionVO:ModuleVersionVO;
        [Bindable] public var selectedModuleVersionIndex:int = 0;
        [Bindable] public var selectedModuleVersionsData:ArrayCollection = new ArrayCollection();
        // This getter strips out any current screen state value in currentApplicationState and
        // returns the remaining int. For example, if currentApplicationState = 333, this returns 330.
        public function get currentScreenState():int {return Utils_LangCollab.getScreenCodeFromApplicationStateCode(currentApplicationState);}

        //public function get selectedChunkId():int {return ChunkVO(selectedModuleVersionChunksData[selectedChunkIndex]).id}

        private var mappedClassReferences:MappedClassReferences = new MappedClassReferences();

        private static var instance:com.langcollab.languagementor.model.MainModel;

        /*public static function getInstance():com.langcollab.languagementor.model.MainModel
        {
            if ( instance == null )
            {
                instance = new com.langcollab.languagementor.model.MainModel();
            }
            return instance;
        }*/

        public function MainModel() 
        {
            dataManager = new DataManager(this);
        }
        /*{
            if ( instance != null )
            {
                Debug.error_Fatal("Don't instantiate MainModel with new() - use getInstance()");
            }
        }*/

        public function getSelectedModuleVersionChunkCount():int
        {
            return dataManager.getModuleVersionChunkCountFromModuleVersionVO(selectedModuleVersionVO);
        }

        public function getSelectedModuleVersionsCount():int
        {
            return selectedModuleVersionsData.length;
        }
    }
}

